<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Rate_star_model extends CI_Model {
 
   function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
	
	public function get_newcar($word)
	{
		$query_string="SELECT * FROM psacar_location where province = " . $this->db->escape($word);
		$result=$this->db->query($query_string,$word);
		return  $result;
	}
	
	public function get_car_list($make, $model, $max_price)
	{
		$extra = "";
		$operator = " AND ";
		if(strlen($make) > 0)
		{
			$extra .= $operator . "make.name = " . $this->db->escape($make);	
		}
		if(strlen($model) > 0)
		{
			$extra .= $operator . "model.name = " . $this->db->escape($model);
		}
		if($max_price > 0)
		{
			$extra .= $operator . "car.price <= " . $this->db->escape($max_price);
		}
		
	  /* if($location > 0)
		{
			$extra .= $operator . "car.price <= " . $this->db->escape($location);
		}*/
		
	 echo "This is value".$extra;
	
		$query_string= "select 
		               car.id as id ,
		               car.price as CarPrice,
				       car.quality as quality,
				       make.name as MakeName,
				       model.name as ModelName,    
				       car.year as YearCreate,
				       type.name as CategoryName
						       
					from    psacar_car as car, 
						     psacar_make as make,
						     psacar_model as model,
						     -- psacar_series as series,
						     psacar_car_type as type
					where  car.series_id =series.id and
					       car.model_id = model.id and 
					       model.make_id = make.id and 
					       car.type_id = type.id and
					       type.name='New Cars'".$extra ;
			//echo $query_string;
		$result=$this->db->query($query_string);
		return  $result;
	}
	
}